//
//  SystemNewsViewCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/4/20.
//  Copyright © 2016年 game. All rights reserved.
//

#import "SystemNewsViewCell.h"
#import "TYAttributedLabel.h"
#import "NSString+HtmlCharact.h"
#import "SysTemNewNotevarModel.h"
#import "MBButtonWithFontAdapter.h"
#import "MBLabelWithFontAdapter.h"
#import "MBTextFieldWithFontAdapter.h"
#import "MBTextViewWithFontAdapter.h"
#import "UIButton+WebCache.h"
@interface SystemNewsViewCell ()
@property (weak, nonatomic) IBOutlet UIButton *head;

@property (weak, nonatomic) IBOutlet MBButtonWithFontAdapter *name;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *time;

@property (weak, nonatomic) IBOutlet TYAttributedLabel *content;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headHeight;
@property (weak, nonatomic) IBOutlet UILabel *footView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iamgeHeight;
@property (weak, nonatomic) IBOutlet UIImageView *backImage;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *footHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentHeight;

@end

@implementation SystemNewsViewCell

- (void)awakeFromNib {
    self.selectionStyle = 0;
    self.footView.backgroundColor = tabPlainBackColor;
    
    self.headHeight.constant = SCREEN_WIDTH*0.07;
    self.headWidth.constant = self.headHeight.constant;
    radius(self.head, self.headHeight.constant/2);
    
   self.backImage.image = [[UIImage imageNamed:@"bg_word"]stretchableImageWithLeftCapWidth:0 topCapHeight:10];
    self.footHeight.constant = SCREEN_HEIGHT*0.03;
    
}

-(void)setModel:(SysTemNewaModel *)model{

    _model = model;
    [self.head sd_setImageWithURL:[NSURL URLWithString:_model.avatar] forState:UIControlStateNormal];
    [self.name setTitle:_model.author forState:UIControlStateNormal];
    
    self.content.backgroundColor = [UIColor clearColor];
    self.time.text = _model.dateline;
    
    NSString *text = [_model.note filterresult];
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];
    // 设置当前文本字体
    [attributedString addAttributeFont:[UIFont systemFontOfSize:SCREEN_WIDTH*0.045]];
    // 追加(添加到最后)属性文本
    [self.content setText:text];
    [self.content sizeToFit];
    
    self.content.preferredMaxLayoutWidth = SCREEN_WIDTH-50;
    CGFloat Hhhh = [self.content getHeightWithWidth:SCREEN_WIDTH-50];
    
    self.contentHeight.constant = Hhhh;
    
    self.iamgeHeight.constant = Hhhh+30;
    self.cellHight = self.iamgeHeight.constant+SCREEN_HEIGHT*0.15;
    
    self.tid = _model.notevar.tid;
}


- (IBAction)spaceGo:(UIButton *)sender {
    
    if ([self.deleget respondsToSelector:@selector(SpaceActionWhithId:)]) {
        [self.deleget SpaceActionWhithId:_model.authorid];
    }
}
@end